﻿using System.Drawing;

namespace ModelLibrary.Image
{
    public class Resources
    {
        public static Bitmap Close(Size size)
        {
            Bitmap image = new Bitmap(size.Width, size.Height);
            using (Graphics graphics = Graphics.FromImage(image))
            {
                using (Brush brush = Brushes.Black)
                {
                    using (Pen pen = new Pen(brush))
                    {
                        graphics.DrawRectangle(pen, 0, 0, size.Width, size.Height);
                        graphics.DrawLine(pen, 0, 0, size.Width, size.Height);
                        graphics.DrawLine(pen, 0, size.Height, size.Width, 0);
                    }
                }
            }
            return image;
        }
        private static void UserCursorBitMap(CtrTypeStyle ctrTypeStyle, string imagePath)
        {
            Size size = new Size();
            string Text = "";
            switch (ctrTypeStyle)
            {
                case CtrTypeStyle.Button:
                    size.Width = 75; size.Height = 23; Text = "按钮";
                    break;
                case CtrTypeStyle.ComboBox:
                    size.Width = 75; size.Height = 23; Text = "下拉框";
                    break;
                case CtrTypeStyle.Label:
                    size.Width = 75; size.Height = 23; Text = "文字描";
                    break;
                case CtrTypeStyle.TextBox:
                    size.Width = 75; size.Height = 23; Text = "文本框";
                    break;
                case CtrTypeStyle.CheckBox:
                    size.Width = 75; size.Height = 23; Text = "多选框";
                    break;
            }
            size.Width += 2; size.Height += 2;
            Bitmap image = new Bitmap(size.Width, size.Height);
            using (Graphics graphics = Graphics.FromImage(image))
            {
                Brush brush = Brushes.DarkSlateGray;

                Pen pen = null;
                pen = new Pen(brush, 1);//静态方法导致无法重复使用
                Font font = new Font("宋体", 11);
                SizeF strSize = graphics.MeasureString(Text, font);
                graphics.DrawRectangle(pen, 0, 0, size.Width, size.Height);
                graphics.DrawString(Text, font, brush, (size.Width - strSize.Width) / 2 - 1, (size.Height - strSize.Height) / 2 + 2);
                //graphics.Clear(Color.MistyRose);

                graphics.Dispose();
                pen.Dispose();
                brush.Dispose();
            }
            image.Save(imagePath);
            image.Dispose();
        }
        public static System.Windows.Forms.Cursor UserControlCursor(CtrTypeStyle ctrTypeStyle)
        {
            string imagePath = "";
            if (!System.IO.Directory.Exists("图标"))
            {
                System.IO.Directory.CreateDirectory("图标");
            }
            switch (ctrTypeStyle)
            {
                case CtrTypeStyle.Button:
                    imagePath = "图标\\Button.png";
                    break;
                case CtrTypeStyle.ComboBox:
                    imagePath = "图标\\ComboBox.png";
                    break;
                case CtrTypeStyle.Label:
                    imagePath = "图标\\Label.png";
                    break;
                case CtrTypeStyle.TextBox:
                    imagePath = "图标\\TextBox.png";
                    break;
                case CtrTypeStyle.CheckBox:
                    imagePath = "图标\\CheckBox.png";
                    break;
            }


            if (!System.IO.File.Exists(imagePath))
                UserCursorBitMap(ctrTypeStyle, imagePath);
            Bitmap bitmapOld = new Bitmap(imagePath);
            Bitmap bitmapNew = new Bitmap(bitmapOld, bitmapOld.Width * 2, bitmapOld.Height * 2);
            Graphics graphics = Graphics.FromImage(bitmapNew);
            graphics.Clear(Color.FromArgb(0, 0, 0, 0));
            graphics.DrawImage(bitmapOld, bitmapOld.Width, bitmapOld.Height, bitmapOld.Width, bitmapOld.Height);

            System.IntPtr intPtr = bitmapNew.GetHicon();

            bitmapOld.Dispose();
            graphics.Dispose();
            bitmapNew.Dispose();
            return new System.Windows.Forms.Cursor(intPtr);
        }
    }
    public enum CursorStyle
    {
        Control,
        FileOper,
        System,
    }
    public enum SizeChangeCursorDirection
    {
        /// <summary>
        /// 默认
        /// </summary>
        None = 0,
        /// <summary>
        /// 上
        /// </summary>
        Top = 1,
        /// <summary>
        /// 左
        /// </summary>
        Left = 2,
        /// <summary>
        /// 右
        /// </summary>
        Right = 4,
        /// <summary>
        /// 下
        /// </summary>
        Bottom = 8,
        /// <summary>
        ///左上
        /// </summary>
        LeftTop = 3,
        /// <summary>
        /// 左下
        /// </summary>
        LeftBottom = 10,
        /// <summary>
        /// 右上
        /// </summary>
        RightTop = 5,
        /// <summary>
        /// 右下
        /// </summary>
        RightBottom = 12,
    }
}
